package com.ewzj.bigdata.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.ewzj.bigdata.R;
import com.ewzj.bigdata.app.constants.AppConstants;
import com.ewzj.bigdata.di.component.DaggerVideoDetailComponent;
import com.ewzj.bigdata.di.module.VideoDetailModule;
import com.ewzj.bigdata.mvp.contract.VideoDetailContract;
import com.ewzj.bigdata.mvp.model.entity.resbean.ArticleBean;
import com.ewzj.bigdata.mvp.model.entity.resbean.NewBean;
import com.ewzj.bigdata.mvp.presenter.VideoDetailPresenter;
import com.ewzj.bigdata.mvp.ui.adapter.NewsAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.jzvd.JZVideoPlayer;
import cn.jzvd.JZVideoPlayerStandard;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class VideoDetailActivity extends BaseActivity<VideoDetailPresenter> implements VideoDetailContract.View {
    @BindView(R.id.videplayer)
    JZVideoPlayerStandard videplayer;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.rv_content)
    RecyclerView rvContent;
    private NewBean newBean;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerVideoDetailComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .videoDetailModule(new VideoDetailModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_video_detail; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        newBean = getIntent().getParcelableExtra(AppConstants.EXTRA_DATA);
        if (newBean == null) {
            killMyself();
        }
        mPresenter.loadVideData();
        mPresenter.loadGuessLikeData();
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public void showVideoView(ArticleBean newBean) {
        if (!TextUtils.isEmpty(newBean.getVideo())){
            videplayer.setUp(newBean.getVideo(), JZVideoPlayer.SCREEN_WINDOW_NORMAL,newBean.getTitle());
            ArmsUtils.obtainAppComponentFromContext(this).imageLoader()
                    .loadImage(this, ImageConfigImpl
                            .builder()
                            .url(newBean.getThumb().get(0))
                            .imageView(videplayer.thumbImageView)
                            .build());
        }
        tvName.setText(newBean.getTitle());
        tvTime.setText("发布于"+newBean.getTime());

    }

    @Override
    public void showGuessLike(List<NewBean> newBeans) {
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        rvContent.setLayoutManager(linearLayoutManager);
        NewsAdapter newsAdapter=new NewsAdapter(newBeans);
        rvContent.setAdapter(newsAdapter);
    }

    @Override
    public NewBean obtainNewbean() {
        return newBean;
    }

    @OnClick({R.id.iv_qq, R.id.iv_sina, R.id.iv_wechat})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_qq:
                break;
            case R.id.iv_sina:
                break;
            case R.id.iv_wechat:
                break;
        }
    }

    @Override
    public void refreshVideo(NewBean newBean) {

    }
}
